<?php

namespace app\admin\model\goods;

use think\Model;


class Goods extends Model
{

    

    

    // 表名
    protected $name = 'goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'authen_text',
        'cate_id_text',
        'cate_id2_text'
    ];
    

    
    public function getAuthenList()
    {
        return ['1' => __('Authen 1'), '2' => __('Authen 2'), '3' => __('Authen 3'), '4' => __('Authen 4')];
    }


    public function getAuthenTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['authen']) ? $data['authen'] : '');
        $list = $this->getAuthenList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    public function getCateIdTextAttr($value, $data)
    {
        $catId = isset($data['cate_id']) ? $data['cate_id'] : 0;
        $name = db('goodscate')->where('id',$catId)->value('name');
        return $name ? $name : '';
    }

    public function getCateId2TextAttr($value, $data)
    {
        $catId = isset($data['cate_id2']) ? $data['cate_id2'] : 0;
        $name = db('goodscate')->where('id',$catId)->value('name');
        return $name ? $name : '';
    }
    public function goodscate()
    {
        return $this->belongsTo('app\admin\model\Goodscate', 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
